package com.tgr.shortLink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tgr.shortLink.admin.common.context.BaseContext;
import com.tgr.shortLink.admin.common.convention.result.Result;
import com.tgr.shortLink.admin.common.convention.result.Results;
import com.tgr.shortLink.admin.remote.ShortLinkActualRemoteService;
import com.tgr.shortLink.admin.remote.ShortLinkRemoteService;
import com.tgr.shortLink.admin.remote.dto.req.LinkCreateReqDTO;
import com.tgr.shortLink.admin.remote.dto.req.LinkPageReqDTO;
import com.tgr.shortLink.admin.remote.dto.req.LinkUpdateReqDTO;
import com.tgr.shortLink.admin.remote.dto.resp.LinkCreateRespDTO;
import com.tgr.shortLink.admin.remote.dto.resp.LinkGroupQueryRespDTO;
import com.tgr.shortLink.admin.remote.dto.resp.LinkPageRespDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述：短链接中台远程调用控制
 * 作者：小陶不慌张
 * 文件：ShortLinkController
 * 日期：2024/1/17 16:52
 */
@RestController(value = "shortLinkControllerAdmin")
@RequiredArgsConstructor
public class ShortLinkController {
    ShortLinkRemoteService shortLinkRemoteService = new ShortLinkRemoteService(){
    };
    private final ShortLinkActualRemoteService shortLinkActualRemoteService;

    @PostMapping("/api/short-link/admin/v1/create")
    public Result<LinkCreateRespDTO> createLink(@RequestBody LinkCreateReqDTO requestParam){
        return shortLinkActualRemoteService.createLink(requestParam);
    }

    @GetMapping("/api/short-link/admin/v1/page")
    public Result<Page<LinkPageRespDTO>> pageLink(LinkPageReqDTO requestParam){
        return shortLinkActualRemoteService.pageLink(requestParam.getGid(),requestParam.getCurrent(),requestParam.getSize());
    }

    @GetMapping("/api/short-link/admin/v1/count")
    public Result<List<LinkGroupQueryRespDTO>> linkCountQuery (@RequestParam("gid") List<String> requestParam){
        return shortLinkActualRemoteService.linkCountQuery(requestParam);
    }

    @PostMapping("/api/short-link/admin/v1/update")
    public Result<Void> pageLink(@RequestBody LinkUpdateReqDTO requestParam){
        shortLinkActualRemoteService.updateLink(requestParam);
        return Results.success();
    }

    @GetMapping("/api/short-link/admin/v1/title")
    public Result<String> getLinkTitle(@RequestParam("url") String url) {

        return shortLinkActualRemoteService.getLinkTitle(url);
    }


}
